<?php
require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';
class RolesDao extends BaseDao
{
    protected $_name;

    public function  _setup() {
        $this->_name = $this->prefix() . "roles";
        parent::_setup();
    }

    public function getRoleById ($role_id)
    {
		$select=$this->db_r->select();
		$select->from($this->_name,"*");
		$select->where('id = ?', $role_id);
        $sql = $select->__toString();
        return $this->db_r->fetchRow($sql);
		
    }
    public function getAllRoles(){
    	$select=$this->db_r->select();
		$select->from($this->_name);
		$sql = $select->__toString();
        return $this->db_r->fetchAll($sql);
    }
    public function updateRoleName ($role_id, $role_name)
    {
        $db = $this->db_w;
        $set = array('role_name' => $role_name);
        $where = $db->quoteInto('id = ?', $role_id);
        return $db->update($this->_name, $set, $where);
    }

    public function updateRole($role,$id){
		$where = $this->db_w->quoteInto('id = ?', $id);
        $this->updateData($role,$where);
    }
   public function deleteRole ($role_id)
    {
        $db = $this->db_w;
        $set = array("is_delete" => 1,'modified'=> date("Y-m-d H:i:s"));
        $where = $db->quoteInto('id = ? ', $role_id);
        $db->update($this->_name, $set, $where);
    }

    public function getRoles(){
        $select = $this->db_r->select();
        $select->from($this->_name,"*");
        $select->where("is_delete = 0");
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }
}
